// 引入
var express = require('express')
// 实例化
var app = express()
// 注册中间件
app.use(express.static('static'))

// post中间件
app.use(express.json())
app.use(express.urlencoded({extended:false}))

var arr = [
    {email:'123213220@qq.com' , name : 'fasasef' , phone : '18888888888' , pass : 'jiaxingege' , ingroup : '卖萌组' , isadmin : 'false' , status: 'false'},
    {email:'11235146220@qq.com' , name : 'asefas' , phone : '18888888888' , pass : 'jiaxingege' , ingroup : '卖萌组' , isadmin : 'false' , status: 'false'},
    {email:'11723426220@qq.com' , name : 'dfasv' , phone : '18888888888' , pass : 'jiaxingege' , ingroup : '卖萌组' , isadmin : 'false' , status: 'false'},
    {email:'1423466220@qq.com' , name : 'sdrhgs' , phone : '18888888888' , pass : 'jiaxingege' , ingroup : '卖萌组' , isadmin : 'false' , status: 'false'},
    {email:'12345220@qq.com' , name : 'gserz' , phone : '18888888888' , pass : 'jiaxingege' , ingroup : '卖萌组' , isadmin : 'false' , status: 'false'},
    {email:'112345220@qq.com' , name : 'AWFSAg' , phone : '186458658' , pass : 'jiaxingege' , ingroup : '卖萌组' , isadmin : 'false' , status: 'false'},
    {email:'112345220@qq.com' , name : 'uiyglkg' , phone : '18456845688' , pass : 'jiaxingege' , ingroup : '卖萌组' , isadmin : 'false' , status: 'false'},
    {email:'112345220@qq.com' , name : 'sdfgg' , phone : '18235112388' , pass : 'jiaxingege' , ingroup : '卖萌组' , isadmin : 'false' , status: 'false'},
    {email:'112345220@qq.com' , name : 'wtryg' , phone : '18827547888' , pass : 'jiaxingege' , ingroup : '卖萌组' , isadmin : 'false' , status: 'false'},
    {email:'112345220@qq.com' , name : 'ajrtg' , phone : '1846234688' , pass : 'jiaxingege' , ingroup : '卖萌组' , isadmin : 'false' , status: 'false'}
]

app.get('/user/search' , (req , res) => {
    var {phone , pass} = req.query
    var flag = null
    arr.map((item) => {
        item.phone == phone ? (flag = 1) : (flag = 0)
    })
    res.send({flag : flag})
})

app.get('/user/home' , (req , res) => {
    var {page , count} = req.query
    var newarr = arr.slice((page - 1 ) * count , page * count)
    console.log(newarr);
    res.send({list:newarr})
})

app.get('/user/sousuo' , (req , res) => {
    var {text} = req.query
    var newarr = arr.filter((item)=>{
        return item.name.indexOf(text) != -1
    })
    res.send({list:newarr})
})

app.listen(8080 ,()=>{console.log(111);})